﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbImageConfigurationTest and is intended
    ///     to contain all TmdbImageConfigurationTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbImageConfigurationTest
    {
        /// <summary>
        ///     A test for TmdbImageConfiguration Constructor
        /// </summary>
        [TestMethod]
        public void TmdbImageConfigurationConstructorTest()
        {
            var target = new TmdbImageConfiguration();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for BackdropSizes
        /// </summary>
        [TestMethod]
        public void BackdropSizesTest()
        {
            var target = new TmdbImageConfiguration();
            var expected = new List<string>();
            target.BackdropSizes = expected;
            var actual = target.BackdropSizes;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for BaseUrl
        /// </summary>
        [TestMethod]
        public void BaseUrlTest()
        {
            var target = new TmdbImageConfiguration();
            string expected = Guid.NewGuid().ToString();
            target.BaseUrl = expected;
            string actual = target.BaseUrl;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for LogoSizes
        /// </summary>
        [TestMethod]
        public void LogoSizesTest()
        {
            var target = new TmdbImageConfiguration();
            var expected = new List<string>();
            target.LogoSizes = expected;
            var actual = target.LogoSizes;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for PosterSizes
        /// </summary>
        [TestMethod]
        public void PosterSizesTest()
        {
            var target = new TmdbImageConfiguration();
            var expected = new List<string>();
            target.PosterSizes = expected;
            var actual = target.PosterSizes;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for ProfileSizes
        /// </summary>
        [TestMethod]
        public void ProfileSizesTest()
        {
            var target = new TmdbImageConfiguration();
            var expected = new List<string>();
            target.ProfileSizes = expected;
            var actual = target.ProfileSizes;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for SecureBaseUrl
        /// </summary>
        [TestMethod]
        public void SecureBaseUrlTest()
        {
            var target = new TmdbImageConfiguration();
            string expected = Guid.NewGuid().ToString();
            target.SecureBaseUrl = expected;
            string actual = target.SecureBaseUrl;
            Assert.AreSame( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\imageConfiguration.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbImageConfiguration();
            var jsonContent = File.ReadAllText( "imageConfiguration.json.txt" );
            var actual = await target.DeserializeJson<TmdbImageConfiguration>( jsonContent );

            Assert.AreEqual( "http://d3gtl9l2a4fn1j.cloudfront.net/t/p/", actual.BaseUrl );
            Assert.AreEqual( "https://d3gtl9l2a4fn1j.cloudfront.net/t/p/", actual.SecureBaseUrl );
            Assert.AreEqual( 6, actual.PosterSizes.Count );
            Assert.AreEqual( 4, actual.BackdropSizes.Count );
            Assert.AreEqual( 4, actual.ProfileSizes.Count );
            Assert.AreEqual( 7, actual.LogoSizes.Count );
        }
    }
}